import React from "react";
import service from "./httpAxios";
import { IdataType, ItagType } from "@/types/type";

//获取标签
export const getTag = () => {
  try {
    const tags = service.get("/tags").then((res) => res.data);
    return tags;
  } catch (e) {
    throw e;
  }
};

//添加标签
export const addTag = (value: ItagType) => {
  try {
    const res = service.post("/tags", value);
    return res;
  } catch (e) {
    throw e;
  }
};

//修改标签
export const editTag = (updata: ItagType) => {
  try {
    const res = service.put("/tags", updata);
    return res;
  } catch (e) {
    throw e;
  }
};

//删除标签
export const deleteTag = (id: string) => {
  try {
    const res = service.delete("/tags", { params: { id: id } });
    return res;
  } catch (e) {
    throw e;
  }
};

//批量删除标签
export const deleteTags = (keys: React.Key[]) => {
  try {
    const res = service.delete("/all/tags", { params: { ids: keys } });
    return res;
  } catch (e) {
    throw e;
  }
};

//获取数据
export const getData = (value: any) => {
  try {
    const data = service.get("/data", { params: value }).then((res) => res.data);
    return data;
  } catch (e) {
    throw e;
  }
};

//删除数据
export const deleteData = (id: string) => {
  try {
    const res = service.delete(`/data/?id=${id}`);
    return res;
  } catch (e) {
    throw e;
  }
};

//添加数据
export const addData = (newdata: IdataType) => {
  try {
    const res = service.post("/data", newdata);
    return res;
  } catch (e) {
    throw e;
  }
};

//修改数据
export const editData = (updata: IdataType) => {
  try {
    const res = service.put("/data", updata);
    return res;
  } catch (e) {
    throw e;
  }
};
